package blackithei.TCP;

import java.io.*;
import java.net.ServerSocket;
import java.net.Socket;

//TCP 字符串数据传输与反馈
public class ServerDemo1 {
    public static void main(String[] args) throws IOException {
        //创建ServerSocket对象
        ServerSocket so=new ServerSocket(10001);
        //等待接收
        Socket accept = so.accept();
        //创建字符缓冲
        BufferedReader bf=new BufferedReader(new InputStreamReader(accept.getInputStream()));
        //读数据
        String line;
        while((line=bf.readLine())!=null){
            System.out.println(line);
        }

        //反馈
        //创建字符缓冲输出流------将字节流转换为字符流
        BufferedWriter buf=new BufferedWriter(new OutputStreamWriter(accept.getOutputStream()));
        buf.write("长河落日圆");
        //刷新流
        buf.flush();

        buf.close();
       //bf.close();
        accept.close();
        so.close();
    }

}
